<template>
	<div>

    <el-form-item   label="所属商家" prop="merchant_id">
      <el-select v-model="form['merchant_id']" placeholder="选择商家" @change="getmerchant_user_id">
        <el-option v-for="(o,i) in list_merchant_group" :key="i" :value="o.merchant_users_id" :label="o.merchant_name"></el-option>
      </el-select>
    </el-form-item>

    <el-form-item v-if="$check_register_field('add','employee_name','/employee_user/view')" label="员工姓名" prop="employee_name">
      <el-input id="employee_name" v-model="form['employee_name']" placeholder="请输入员工姓名" ></el-input>
    </el-form-item>

    <el-form-item v-if="$check_register_field('add','employee_phone','/employee_user/view')" label="员工电话" prop="employee_phone">
      <el-input id="employee_phone" v-model="form['employee_phone']" placeholder="请输入员工电话" ></el-input>
    </el-form-item>

	</div>
</template>

<script>
	import mixin from "@/mixins/component.js";

	export default {
		mixins: [mixin],
		props:{

			form:{
				type: Object,
				default: function(){
					return {
            "employee_name":  '' ,
            "employee_phone":  '' ,
            "merchant_id":'',
            "merchant_user_id":''
						}
				}
			},

		},
		data() {
			return {
				field: "employee_user_id",
				url_add: "~/api/employee_user/add?",
				url_set: "~/api/employee_user/set?",
				url_upload: "~/api/employee_user/upload?",

        rules: {
					"employee_name": [    {required: true,message: '员工姓名不能为空'},  ],
					"employee_phone": [    {required: true,message: '员工电话不能为空'},  ],
					"merchant_id": [    {required: true,message: '请选择商家'},  ],
				},
        list_merchant_group:[],

			}
		},
		methods: {
      async getmerchant_user_id(merchant_users_id){
        var json =await this.$get("~/api/merchant_users/get_obj?merchant_users_id="+merchant_users_id);
        if(json.result != null){
          var obj = json.result.obj;
          this.form.merchant_user_id = obj.user_id;
        } else{
          console.error(json.error);
        }

      },
      async get_list_merchant_group(){
        var json = await this.$get("~/api/merchant_users/get_list");
        if(json.result && json.result.list){
          this.list_merchant_group = json.result.list;
        } else{
          console.error(json.error);
        }
      },
    },
		created() {
      this.get_list_merchant_group();
    }
	}
</script>
